package com.zara.store.client.view.swing.table;


public class PalcTableModel extends StoreTableModel {
	
	private static final int ORDERED_AMOUNT = 2;
	private static final long serialVersionUID = 1L;
	private boolean modifiable;
	
	public PalcTableModel() {
		super();
		this.setColumnIdentifiers(new Object[]{
				"Codigo", "Producto", "Cantidad", "Disp. OfAD", 
				"Ult. Sem.", "Pend. PaLC", "Stock", "Punto pedido"});
//		this.addRow(new Object[]{"12","papas","0","Disponible","1","1","1","10"});
//		this.addRow(new Object[]{"13","papas papas","0","-","1","1","1","20"});
	}

	public Class<?> getColumnClass(int columnIndex) {
		return String.class;
	}
	
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return (columnIndex==ORDERED_AMOUNT)? modifiable:false;
	}
	
	private TableOnChangeAction amountAction;

	public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
		super.setValueAt(aValue, rowIndex, columnIndex);
		if(columnIndex==ORDERED_AMOUNT) { //cambia cantidad pedida
			amountAction.onChange(rowIndex, aValue.toString());
		}
	}

	public void setOnChangeAmountAction(TableOnChangeAction action) {
		this.amountAction = action;
	}

	public void setModifiable(boolean b) {
		this.modifiable = b;
	}

};
